// JavaScript Document


/*
kaleite onClick apo ena pedio select pernei tin marka pou epileksame
kai apo katw sto div model view emfanizei ola ta montela tis sugekrimenis markas
kathws kai ta upoloipa kritiria anazitisis
*/

function view_models(marka){
	var marka=document.getElementById("select_brand").value;

	ajaxObj=new XMLHttpRequest();

	ajaxObj.onreadystatechange=
	function checkReady()
	{
		if(ajaxObj.readyState==4) 
		{
			$('#models_view')
			.empty()
			.append(ajaxObj.responseText);
		}
	};
	ajaxObj.open("GET","search_form.php"+"?marka="+marka,true);
	ajaxObj.send(null);
}

    
	/*
		onclick emfanisi twn datepicker stin selida anazitisis
	*/
	
	$(document).ready(function()
	{
	$('#datepicker_from').datepicker({dateFormat: 'yy-mm-dd'})
	})
	
	$(document).ready(function()
	{
		$('#datepicker_to').datepicker({dateFormat: 'yy-mm-dd'})
	})
	


//elegxos imerominias an to from einai mikrotero apo to to
function check_date()
	{	
		 var date_from = document.getElementById('datepicker_from').value;
		 var date_to = document.getElementById('datepicker_to').value;
		 if(date_from>date_to)
		 {
		  	 alert("The date From (" + date_from + ") is bigger that the date To (" + date_to + ")");
			 return false;
		 }
		 
		 if(date_from=="" || date_to=="")
		 {
			alert("Empty Date Fileds... Please fill the Dates");
			return false;	 
		 }
		 
		 
		 current_date = new Date();
		 date_from = new Date(date_from);
		 if(date_from<current_date)
		 {
			alert('The date you chose to start the order has already passed or is today!!!-Orders are accepted after a one day notice at least-');
			return false;
		 }
	}
	
	
function check_register()
{
	var fname = document.getElementById('first_name').value;
	var lname = document.getElementById('last_name').value;
	var username = document.getElementById('username').value;
	var password = document.getElementById('password').value;
	var date = document.getElementById('date').value;
	var year = document.getElementById('date').value.split("-")[0];
	var month = document.getElementById('date').value.split("-")[1];
	var day = document.getElementById('date').value.split("-")[2];
		
		if(lname=="" || lname.length>20)
		{
			alert("Invalud input on Last Name. Should not be blank or bigger than 20 characters");
			return false;	
		}
		
		if(fname=="" || fname.length>20)
		{
			alert("Invalud input on First Name. Should not be blank or bigger than 20 characters");
			return false;	
		}
		
		if(date.indexOf('/' , '.')!= -1 || date.length<10)
		{
			alert("Check below for the proper date format.");
			return false;	
		}
		
		if(year.length<4||year<1900||year>2012)
		{
			alert("Invalid birth year input");
			return false;	
		}
		
		if(month.length>2 || month<1 || month>12)
		{
			alert("Invalid month input");
			return false;	
		}
		
		if(day<0||day>31)
		{
			alert('Invalid day input');	
			return false;
		}
		
		if(month==2 && day>29)
		{
			alert("February mistake");
			return false;	
		}
}
	
